/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        if(null == head) {
            return null;
        }
        if(val == head.val) {
            head = head.next;
            return head;
        }
        ListNode cur = head;
        ListNode prev = null;
        while(val != cur.val && null != cur) {
            prev = cur;
            cur = cur.next;
        }
        if(null != cur) {
            prev.next = cur.next;
        }
        return head;

    }
}